

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>&lt;no title&gt; &mdash; agpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="_static/extra.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="agpy 0.1.2 documentation" href="index.html" />
     
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setDomainName', 'pyspeckit.bitbucket.org']);
      _gaq.push(['_setAllowHash', false]);
      _gaq.push(['_trackPageview']);


    </script>
    <link rel="stylesheet" type="text/css" href="_static/extra.css" />
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="index.html">agpy 0.1.2 documentation</a></h1>
        <div class="rel">
          <a href="http://agpy.googlecode.com">agpy Home </a>  |
          <a href=index.html>Docs Home </a>  |
          <a href="http://code.google.com/p/agpy/w/list">Wiki</a>  |
          <a href=search.html>Search </a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-agpy.gaussfitter"></span><p>Latest version available at &lt;<a class="reference external" href="http://code.google.com/p/agpy/source/browse/trunk/agpy/gaussfitter.py">http://code.google.com/p/agpy/source/browse/trunk/agpy/gaussfitter.py</a>&gt;</p>
<dl class="function">
<dt id="agpy.gaussfitter.gaussfit">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">gaussfit</tt><big>(</big><em>data, err=None, params=(), autoderiv=True, return_all=False, circle=False, fixed=array([False, False, False, False, False, False, False], dtype=bool), limitedmin=[False, False, False, False, True, True, True], limitedmax=[False, False, False, False, False, False, True], usemoment=array([], dtype=bool), minpars=array([0, 0, 0, 0, 0, 0, 0]), maxpars=[0, 0, 0, 0, 0, 0, 360], rotate=1, vheight=1, quiet=True, returnmp=False, returnfitimage=False, **kwargs</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#gaussfit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.gaussfit" title="Permalink to this definition">¶</a></dt>
<dd><p>Gaussian fitter with the ability to fit a variety of different forms of
2-dimensional gaussian.</p>
<dl class="docutils">
<dt>Input Parameters:</dt>
<dd><p class="first">data - 2-dimensional data array
err=None - error array with same size as data array
params=[] - initial input parameters for Gaussian function.</p>
<blockquote>
<div>(height, amplitude, x, y, width_x, width_y, rota)
if not input, these will be determined from the moments of the system, 
assuming no rotation</div></blockquote>
<dl class="docutils">
<dt>autoderiv=1 - use the autoderiv provided in the lmder.f function (the</dt>
<dd>alternative is to us an analytic derivative with lmdif.f: this method
is less robust)</dd>
<dt>return_all=0 - Default is to return only the Gaussian parameters.  </dt>
<dd>1 - fit params, fit error</dd>
</dl>
<p>returnfitimage - returns (best fit params,best fit image)
returnmp - returns the full mpfit struct
circle=0 - default is an elliptical gaussian (different x, y widths),</p>
<blockquote>
<div>but can reduce the input by one parameter if it&#8217;s a circular gaussian</div></blockquote>
<dl class="last docutils">
<dt>rotate=1 - default allows rotation of the gaussian ellipse.  Can remove</dt>
<dd>last parameter by setting rotate=0.  numpy.expects angle in DEGREES</dd>
<dt>vheight=1 - default allows a variable height-above-zero, i.e. an</dt>
<dd>additive constant for the Gaussian function.  Can remove first
parameter by setting this to 0</dd>
<dt>usemoment - can choose which parameters to use a moment estimation for.</dt>
<dd>Other parameters will be taken from params.  Needs to be a boolean
array.</dd>
</dl>
</dd>
<dt>Output:</dt>
<dd><dl class="first docutils">
<dt>Default output is a set of Gaussian parameters with the same shape as</dt>
<dd>the input parameters</dd>
<dt>Can also output the covariance matrix, &#8216;infodict&#8217; that contains a lot</dt>
<dd>more detail about the fit (see scipy.optimize.leastsq), and a message
from leastsq telling what the exit status of the fitting routine was</dd>
</dl>
<p class="last">Warning: Does NOT necessarily output a rotation angle between 0 and 360 degrees.</p>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.moments">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">moments</tt><big>(</big><em>data</em>, <em>circle</em>, <em>rotate</em>, <em>vheight</em>, <em>estimator=&lt;function median at 0x1037f9488&gt;</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#moments"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.moments" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (height, amplitude, x, y, width_x, width_y, rotation angle)
the gaussian parameters of a 2D distribution by calculating its
moments.  Depending on the input parameters, will only output 
a subset of the above.</p>
<p>If using masked arrays, pass estimator=numpy.ma.median</p>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.multigaussfit">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">multigaussfit</tt><big>(</big><em>xax, data, ngauss=1, err=None, params=[1, 0, 1], fixed=[False, False, False], limitedmin=[False, False, True], limitedmax=[False, False, False], minpars=[0, 0, 0], maxpars=[0, 0, 0], quiet=True, shh=True, veryverbose=False</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#multigaussfit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.multigaussfit" title="Permalink to this definition">¶</a></dt>
<dd><p>An improvement on onedgaussfit.  Lets you fit multiple gaussians.</p>
<dl class="docutils">
<dt>Inputs:</dt>
<dd><blockquote class="first">
<div>xax - x axis
data - y axis
ngauss - How many gaussians to fit?  Default 1 (this could supersede onedgaussfit)
err - error corresponding to data</div></blockquote>
<p>These parameters need to have length = 3*ngauss.  If ngauss &gt; 1 and length = 3, they will
be replicated ngauss times, otherwise they will be reset to defaults:</p>
<blockquote class="last">
<div><dl class="docutils">
<dt>params - Fit parameters: [amplitude, offset, width] * ngauss</dt>
<dd>If len(params) % 3 == 0, ngauss will be set to len(params) / 3</dd>
</dl>
<p>fixed - Is parameter fixed?
limitedmin/minpars - set lower limits on each parameter (default: width&gt;0)
limitedmax/maxpars - set upper limits on each parameter</p>
<p>quiet - should MPFIT output each iteration?
shh - output final parameters?</p>
</div></blockquote>
</dd>
<dt>Returns:</dt>
<dd>Fit parameters
Model
Fit errors
chi2</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.n_gaussian">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">n_gaussian</tt><big>(</big><em>pars=None</em>, <em>a=None</em>, <em>dx=None</em>, <em>sigma=None</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#n_gaussian"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.n_gaussian" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a function that sums over N gaussians, where N is the length of
a,dx,sigma <em>OR</em> N = len(pars) / 3</p>
<p>The background &#8220;height&#8221; is assumed to be zero (you must &#8220;baseline&#8221; your
spectrum before fitting)</p>
<p>pars  - a list with len(pars) = 3n, assuming a,dx,sigma repeated
dx    - offset (velocity center) values
sigma - line widths
a     - amplitudes</p>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.onedgaussfit">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">onedgaussfit</tt><big>(</big><em>xax, data, err=None, params=[0, 1, 0, 1], fixed=[False, False, False, False], limitedmin=[False, False, False, True], limitedmax=[False, False, False, False], minpars=[0, 0, 0, 0], maxpars=[0, 0, 0, 0], quiet=True, shh=True, veryverbose=False, vheight=True, negamp=False, usemoments=False</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#onedgaussfit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.onedgaussfit" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt>Inputs:</dt>
<dd><p class="first">xax - x axis
data - y axis
err - error corresponding to data</p>
<p class="last">params - Fit parameters: Height of background, Amplitude, Shift, Width
fixed - Is parameter fixed?
limitedmin/minpars - set lower limits on each parameter (default: width&gt;0)
limitedmax/maxpars - set upper limits on each parameter
quiet - should MPFIT output each iteration?
shh - output final parameters?
usemoments - replace default parameters with moments</p>
</dd>
<dt>Returns:</dt>
<dd>Fit parameters
Model
Fit errors
chi2</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.onedgaussian">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">onedgaussian</tt><big>(</big><em>x</em>, <em>H</em>, <em>A</em>, <em>dx</em>, <em>w</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#onedgaussian"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.onedgaussian" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a 1-dimensional gaussian of form
H+A*numpy.exp(-(x-dx)**2/(2*w**2))</p>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.onedmoments">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">onedmoments</tt><big>(</big><em>Xax</em>, <em>data</em>, <em>vheight=True</em>, <em>estimator=&lt;function median at 0x1037f9488&gt;</em>, <em>negamp=None</em>, <em>veryverbose=False</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#onedmoments"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.onedmoments" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (height, amplitude, x, width_x)
the gaussian parameters of a 1D distribution by calculating its
moments.  Depending on the input parameters, will only output 
a subset of the above.</p>
<p>If using masked arrays, pass estimator=numpy.ma.median
&#8216;estimator&#8217; is used to measure the background level (height)</p>
<p>negamp can be used to force the peak negative (True), positive (False),
or it will be &#8220;autodetected&#8221; (negamp=None)</p>
</dd></dl>

<dl class="function">
<dt id="agpy.gaussfitter.twodgaussian">
<tt class="descclassname">agpy.gaussfitter.</tt><tt class="descname">twodgaussian</tt><big>(</big><em>inpars</em>, <em>circle=False</em>, <em>rotate=True</em>, <em>vheight=True</em>, <em>shape=None</em><big>)</big><a class="reference internal" href="_modules/agpy/gaussfitter.html#twodgaussian"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#agpy.gaussfitter.twodgaussian" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a 2d gaussian function of the form:
x&#8217; = numpy.cos(rota) * x - numpy.sin(rota) * y
y&#8217; = numpy.sin(rota) * x + numpy.cos(rota) * y
(rota should be in degrees)
g = b + a * numpy.exp ( - ( ((x-center_x)/width_x)**2 +
((y-center_y)/width_y)**2 ) / 2 )</p>
<dl class="docutils">
<dt>inpars = [b,a,center_x,center_y,width_x,width_y,rota]</dt>
<dd>(b is background height, a is peak amplitude)</dd>
</dl>
<p>where x and y are the input parameters of the returned function,
and all other parameters are specified by this function</p>
<p>However, the above values are passed by list.  The list should be:
inpars = (height,amplitude,center_x,center_y,width_x,width_y,rota)</p>
<dl class="docutils">
<dt>You can choose to ignore / neglect some of the above input parameters </dt>
<dd><p class="first">unumpy.sing the following options:
circle=0 - default is an elliptical gaussian (different x, y</p>
<blockquote>
<div>widths), but can reduce the input by one parameter if it&#8217;s a
circular gaussian</div></blockquote>
<dl class="last docutils">
<dt>rotate=1 - default allows rotation of the gaussian ellipse.  Can</dt>
<dd>remove last parameter by setting rotate=0</dd>
<dt>vheight=1 - default allows a variable height-above-zero, i.e. an</dt>
<dd>additive constant for the Gaussian function.  Can remove first
parameter by setting this to 0</dd>
<dt>shape=None - if shape is set (to a 2-parameter list) then returns</dt>
<dd>an image with the gaussian defined by inpars</dd>
</dl>
</dd>
</dl>
</dd></dl>



          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul>
<li class="toctree-l1"><a class="reference internal" href="agpy.html">Adam Ginsburg&#8217;s Python Code (agpy)</a></li>
<li class="toctree-l1"><a class="reference internal" href="image_tools.html">Image Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="fft_tools.html">AG_fft_tools Package</a></li>
<li class="toctree-l1"><a class="reference internal" href="plfit.html">plfit Package</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="search.html" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer">
      &copy; Copyright 2011, Adam Ginsburg.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2pre.
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-6253248-2']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
        
    </div>
  </body>
</html>